
	//fileName：用于获取到用户所选文件的名称，这和直接取value值所获得的成果一样。
	//fileSize：获得用户所选文件的大小。
	//Math.floor  想下取整 3.999==3  3.111==3   -3.13==-4  -5.999==-6;
	//常见的变量
	var iBytesUploaded = 0;  //已上传的字节数
	var iBytesTotal = 0;  //总字节
	var iPreviousBytesLoaded = 0;    //加载的字节
	var iMaxFilesize = 100048576; // 1MB  //文件的最大尺寸
	var oTimer = 0;
	var sResultFileSize = '';   //文档结果大小

	function secondsToTime(secs) { // 将正常的时间转换为时、分、秒
	    var hr = Math.floor(secs / 3600);  //时
	    var min = Math.floor((secs - (hr * 3600))/60);  //分
	    var sec = Math.floor(secs - (hr * 3600) -  (min * 60));  //秒
	
	    if (hr < 10) {hr = "0" + hr; }
	    if (min < 10) {min = "0" + min;}
	    if (sec < 10) {sec = "0" + sec;}
	    if (hr) {hr = "00";}
	    return hr + ':' + min + ':' + sec;
	};

	function bytesToSize(bytes) {        //判断传入字节的大小 
	    var sizes = ['Bytes', 'KB', 'MB'];
	    if (bytes == 0) return 'n/a';
	    var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
	    return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
	    //Math.pow(1024, i) 返回1024的i次幂(类似于多少个1024相乘几次,i几就相乘几)
	    //.toFixed(1) 把数字转换为字符串，结果的小数点后有指定位数的数字  5.567676766===5.6
	};

	function startUploading() {
	    //清理所有状态
	    iPreviousBytesLoaded = 0;
	    document.getElementById('upload_response').style.display = 'none';
	    document.getElementById('error').style.display = 'none';
	    document.getElementById('error2').style.display = 'none';
	    document.getElementById('abort').style.display = 'none';
	    document.getElementById('warnsize').style.display = 'none';
	    document.getElementById('progress_percent').innerHTML = '';
	    var oProgress = document.getElementById('progress');
	    oProgress.style.display = 'block';
	    oProgress.style.width = '0px';
	
	    //获取张贴的表格数据 
	    //是document.getelementbyid VFD =（上传_形式）.getformdata（）；//在FF3 
	    //readAsDataURL方法用于读取指定Blob或File的内容。当读操作完成，readyState变为DONE, loadend被触发，此时result属性包含数据：URL以base64编码的字符串表示文件的数据。
	    var vFD = new FormData(document.getElementById('upload_form')); 
	
	    // 创建XMLHttpRequest对象，添加一些事件监听器，并发布我们的数据
	    var oXHR = new XMLHttpRequest();        
	    oXHR.upload.addEventListener('progress', uploadProgress, false);  //进度条
	    oXHR.addEventListener('load', uploadFinish, false);                 //当...加载时
	    oXHR.addEventListener('error', uploadError, false);             //当...错误时
	    oXHR.addEventListener('abort', uploadAbort, false);            //当...异常终止时
	    oXHR.open('POST', 'upload.php');
	    oXHR.send(vFD);
	
	    //设置内部定时器 
	    oTimer = setInterval(doInnerUpdates, 300);
	}

		function doInnerUpdates() { //我们将使用此功能来显示上传速度 
		    var iCB = iBytesUploaded;    //已上传的字节
		    alert("icb"+iCB);
		    var iDiff = iCB - iPreviousBytesLoaded; //iPreviousBytesLoaded加载的字节		
		    // 如果没有新的加载-退出
		    alert("iDiff"+iDiff);
		    alert("iPreviousBytesLoaded"+iPreviousBytesLoaded);
		    if (iDiff == 0)
		        return;
		
		    iPreviousBytesLoaded = iCB;
		    iDiff = iDiff * 2;
		    var iBytesRem = iBytesTotal - iPreviousBytesLoaded;   //iBytesTotal 总字节
		    var secondsRemaining = iBytesRem / iDiff;
		
		    // 信息更新速度
		    var iSpeed = iDiff.toString() + 'B/s';
		    if (iDiff > 1024 * 1024) {
		        iSpeed = (Math.round(iDiff * 100/(1024*1024))/100).toString() + 'MB/s';
		    } else if (iDiff > 1024) {
		        iSpeed =  (Math.round(iDiff * 100/1024)/100).toString() + 'KB/s';
		    }
		    document.getElementById('speed').innerHTML = iSpeed;
		    document.getElementById('remaining').innerHTML = '| ' + secondsToTime(secondsRemaining);        
		}

		function uploadProgress(e) { // 进度上传过程
		    if (e.lengthComputable) {
		        iBytesUploaded = e.loaded;   
		        iBytesTotal = e.total;
		        var iPercentComplete = Math.round(e.loaded * 100 / e.total);
		        var iBytesTransfered = bytesToSize(iBytesUploaded);
		        var iBytesTotals = bytesToSize(iBytesTotal);
		
		        document.getElementById('progress_percent').innerHTML = iPercentComplete.toString() + '%';
		        document.getElementById('progress').style.width = (iPercentComplete * 4).toString() + 'px';
		        document.getElementById('b_transfered').innerHTML = iBytesTransfered;
		        document.getElementById('num').innerHTML=iBytesTotals;
		        if (iPercentComplete == 100) {
		            var oUploadResponse = document.getElementById('upload_response');
		            oUploadResponse.innerHTML = '<h1>Please wait...processing</h1>';
		            oUploadResponse.style.display = 'block';
		        }
		    } else {
		        document.getElementById('progress').innerHTML = 'unable to compute';
		    }
		}

		function uploadFinish(e) { // 上传成功完成
		    var oUploadResponse = document.getElementById('upload_response');
		    oUploadResponse.innerHTML = e.target.responseText;
		    oUploadResponse.style.display = 'block';
		
		    document.getElementById('progress_percent').innerHTML = '100%';
		    document.getElementById('progress').style.width = '400px';
		    document.getElementById('filesize').innerHTML = sResultFileSize;
		    //document.getElementById('remaining').innerHTML = '| 00:00:00';
		
		    clearInterval(oTimer);
		}

		function uploadError(e) { // 上传错误
		    document.getElementById('error2').style.display = 'block';
		    clearInterval(oTimer);
		}  
		
		function uploadAbort(e) { // 上传失败
		    document.getElementById('abort').style.display = 'block';
		    clearInterval(oTimer);
		}

